package com.example.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String users = (String) request.getSession().getAttribute("Users");
        if("".equals(users) || users==null){
            response.sendRedirect(request.getContextPath() + "/login/toLogin");
            return false;
        }
        //System.out.println("MyInterceptor01 preHandle...");
        return true;
    }

}
